package us.icitap.timsportal.entity;

import us.icitap.timsportal.entity.Officer;
import java.io.Serializable;
import java.lang.String;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.*;

/**
 * Entity implementation class for Entity: User
 *
 */
@Entity
@Table(name="USERS", schema="TIMSPORTAL")
@SequenceGenerator(name = "user_seq", sequenceName = "TIMSPORTAL.SQ_TIMSPORTAL_USER", allocationSize = 1)
public class User implements Serializable {

	   
	/**
	 * 
	 */
	private static final long serialVersionUID = -1824099299682496969L;
	@Id
	@GeneratedValue(generator="user_seq")
	private Integer id;
	private String username;
	@Column(name="START_DATE")
	@Temporal(TemporalType.DATE)
	private Date startDate;
	@Column(name="END_DATE")
	@Temporal(TemporalType.DATE)
	private Date endDate;
	@Column(name="RECORD_DATE")
	@Temporal(TemporalType.TIMESTAMP)
	private Date recordDate;
	@Column(name="RECORD_USER")
	private String recordUser;
	@Column(name="LAST_UPDATE_DATE")
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastUpdateDate;
	private boolean active;
	@Column(name="RMIS_OFFICER")
	private boolean rmisOfficer;
	@ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.MERGE})
	@JoinColumn(name="OFFICER_ID")
	private Officer officer;
	@ManyToMany(cascade={CascadeType.MERGE},fetch=FetchType.EAGER)
	@JoinTable(name="TIMSPORTAL.USER_ROLE", 
			joinColumns={@JoinColumn(name="USER_ID")},
			inverseJoinColumns={@JoinColumn(name="ROLE_ID")}
	)
	private Set<Role> roles = new HashSet<Role>();
	@Column(name="NAME", length=30)
	private String name;
	@Column(name="SURNAME", length=30)
	private String surname;
	@Column(name="FUNCTION", length=100)
	private String function;
	@Column(name="STRUCTURE", length=100)
	private String structure;
	@Column(name="EMAIL", length=100)
	private String email;
	
	@JoinColumn(name="BASE_STRUCTURE")
	@ManyToOne(fetch=FetchType.EAGER)
	private OrgStructure baseStructure;

	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public User() {
		super();
	}   
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}   
	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}   
	public Date getStartDate() {
		return this.startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}   
	public Date getEndDate() {
		return this.endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}   
	public Date getRecordDate() {
		return this.recordDate;
	}

	public void setRecordDate(Date recordDate) {
		this.recordDate = recordDate;
	}   
	public String getRecordUser() {
		return this.recordUser;
	}

	public void setRecordUser(String recordUser) {
		this.recordUser = recordUser;
	}   
	public Date getLastUpdateDate() {
		return this.lastUpdateDate;
	}

	public void setLastUpdateDate(Date lastUpdateDate) {
		this.lastUpdateDate = lastUpdateDate;
	}   
	public Officer getOfficer() {
		return this.officer;
	}

	public void setOfficer(Officer officer) {
		this.officer = officer;
	}
	public Set<Role> getRoles() {
		return roles;
	}
	public void setRoles(Set<Role> roles) {
		HashSet<Role> r = new HashSet<Role>();
		if(r!=null)
		r.addAll(roles);		
		this.roles = r;
	}
	public boolean isActive() {
		return active;
	}
	public void setActive(boolean active) {
		this.active = active;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getSurname() {
		return surname;
	}
	public void setSurname(String surname) {
		this.surname = surname;
	}
	public String getFunction() {
		return function;
	}
	public void setFunction(String function) {
		this.function = function;
	}
	public String getStructure() {
		return structure;
	}
	public void setStructure(String structure) {
		this.structure = structure;
	}
	public OrgStructure getBaseStructure() {
		return baseStructure;
	}
	public void setBaseStructure(OrgStructure baseStructure) {
		this.baseStructure = baseStructure;
	}
	public boolean isRmisOfficer() {
		return rmisOfficer;
	}
	public void setRmisOfficer(boolean rmisOfficer) {
		this.rmisOfficer = rmisOfficer;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((email == null) ? 0 : email.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((username == null) ? 0 : username.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof User))
			return false;
		User other = (User) obj;
		if (email == null) {
			if (other.email != null)
				return false;
		} else if (!email.equals(other.email))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (username == null) {
			if (other.username != null)
				return false;
		} else if (!username.equals(other.username))
			return false;
		return true;
	}

   
}
